package com.seas.support;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;

import javax.persistence.EntityManager;
import java.io.Serializable;
import java.util.List;

import static com.seas.specs.CustomeSpecs.*;

/**
 * Created by Seas Cheng on 2017/9/26
 */
public class CustomRespositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements CustomRespository<T, ID>{
    private final EntityManager entityManager;
    public CustomRespositoryImpl(Class<T> domainClass, EntityManager entityManager){
        super(domainClass, entityManager);
        this.entityManager = entityManager;
    }

    @Override
    public Page<T> findByAuto(T example, Pageable pageable) {
        return findAll(byAuto(entityManager, example), pageable);
    }
    @Override
    public List<T> findBySortAuto(T example,Sort sort) {
        return findAll(byAuto(entityManager, example), sort);
    }
}
